﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Evolution.Structure.Globe
{
    public class Resource
    {

        public ValueType Type { get; set; }
        public double Value { get; set; }


        public Resource(ValueType type, double value)
        {
            this.Value = value;
            this.Type = type;
        }

        /// <summary>
        /// Overload the + Operator to sum up the resources
        /// </summary>
        /// <param name="res1"></param>
        /// <param name="res2"></param>
        /// <returns></returns>
        public static Resource operator +(Resource res1, Resource res2)
        {
            if (res1.Type.Equals(ValueType.Absolute) && res2.Type.Equals(ValueType.Absolute))
            {
                return new Resource(ValueType.Absolute, res1.Value + res2.Value);
            }
            else if (res1.Type.Equals(ValueType.Absolute) && res2.Type.Equals(ValueType.Relative)) //sample: 5 + 20%
            {
                return new Resource(ValueType.Absolute, res1.Value + res1.Value * res2.Value);
            }
            else if (res1.Type.Equals(ValueType.Relative) && res2.Type.Equals(ValueType.Absolute)) //sample: 5 + 20%
            {
                return new Resource(ValueType.Absolute, res2.Value + res2.Value * res1.Value);
            }
            else //sample: 5% + 20%
            {
                return new Resource(ValueType.Relative, res1.Value + res2.Value);
            } 
        }

    }
}
